<template>
  <div class="page_vue_door">
    <div class="page_header">
      <div class="hearder_search">
        <search-header pageType="team"></search-header>
      </div>
    </div>
    <div class="page_body">
      <div class="page_left div_box">
        <div class="item_box yellow_colour ">
          <div class="item_title">
            <div class="title_text">收藏文件</div>
            <div>{{ teamCount.collection }}</div>
          </div>
          <div class="item_icon">
            <svg-icon icon-class="collect-fill" style="font-size:40px"></svg-icon>
          </div>
        </div>
        <div class="item_box green_colour">
          <div class="item_title ">
            <div class="title_text">团队分类</div>
            <div>{{ teamCount.team }}</div>
          </div>
          <div class="item_icon">
            <svg-icon icon-class="describe" style="font-size:40px"></svg-icon>
          </div>
        </div>
        <div class="item_box blue_colour" style="margin-bottom:0">
          <div class="item_title">
            <div class="title_text">分发接收</div>
            <div>{{ teamCount.distribute }}</div>
          </div>
          <div class="item_icon">
            <svg-icon icon-class="shuffle" style="font-size:40px"></svg-icon>
          </div>
        </div>
      </div>
      <div class="page_right">
        <div class="right_top">
          <div class="recently_tool div_box">
            <div class="div_title">常用功能</div>
            <div class="recently_tool_box">
              <div v-for="(item, index) in routerList" :key="index">
                <div class="box_item" @click="gotoPage(item)">
                  <div class="icon_box">
                    <svg-icon :icon-class="item.icon ? item.icon : 'schedule-all'" :style="{ color: item.color }" />
                  </div>
                  <div class="title">{{ item.title }}</div>
                </div>
              </div>
            </div>
          </div>
          <div class="common_team div_box">
            <div class="div_title">常用团队</div>
            <div v-if="LatelyTeamList.length != 0">
              <div v-for="(item, index) in LatelyTeamList.slice(0, 4)" :key="index" @click="skipTeamClick(item)">
                <el-row class="common_team_box">
                  <el-col :lg="13">
                    <svg-icon icon-class="xiangmutuandui"
                      style="font-size: 30px;vertical-align: middle; margin-right: 4px;" />
                    <span class="teamName">{{ item.teamName }}</span>
                  </el-col>
                  <el-col :lg="6" class="hidden-md-and-down">
                    <div class="peopleBox">
                      <div class="people">
                        <span>
                          {{ item.createBy.slice(-2) }}
                        </span>
                      </div>
                      {{ item.createBy }}
                    </div>
                  </el-col>
                  <el-col :lg="5" style="text-align: right;">
                    <el-progress type="circle" :percentage="item.useOfSpace" :width="42"></el-progress>
                  </el-col>
                </el-row>
              </div>
            </div>
            <el-empty v-else description="暂无数据"></el-empty>
          </div>
        </div>
        <div class="right_bottom_box div_box">
          <div class="div_title">团队分类数量</div>
          <section class="echarts_class" ref="echartsRefs"></section>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import * as echarts from "echarts"
import SearchHeader from './components/search-header.vue' //搜索
import { apiTeamGetLatelyTeam, apiTeamTypeTeamCount, apiTeamTypeTeamTypeCount } from '@/api/teamKnowdge/teamDoorApi'
const router = useRouter()
const teamCount = ref({
  collection: 0,
  team: 0,
  distribute: 0
})
const routerList = ref([
  { title: "文件收藏", icon: "collect-fill", path: "/newUi/teamKnowdge/teamCollect", color: "#ffdc53" },
  { title: "团队分类", icon: "nested", path: "/newUi/teamKnowdge/teamClassify", color: "#73d897" },
  { title: "高级搜索", icon: "search", path: "/newUi/teamKnowdge/teamSearch", color: "#57faca" },
  { title: "分发接收", icon: "shuffle", path: "/newUi/teamKnowdge/teamDistribute", color: "#5598ff" }
])
const LatelyTeamList = ref([])
const route = useRoute()
const xAxisDataList = ref([])
const seriesData = ref([])
const echartsRefs = ref(null)

const getDataCount = () => {
  apiTeamTypeTeamCount({
    page: 0,
    size: 1
  })
    .then((res) => {
      teamCount.value = res.data
    })
}

// 获取常用团队
const getCommonTeam = async () => {
  const res = await apiTeamGetLatelyTeam()
  if (res.code == 200) {
    LatelyTeamList.value = res.data

  }
}

const gotoPage = (item: any) => {
  router.push(item.path)
}
const skipTeamClick = (row: any) => {
  // sessionStorage.setItem("type", JSON.stringify(row.type))
  // if (route.path == '/newUi/teamKnowdge/teamDoc') {
  //   router.push({ path: '/newUi/teamKnowdge/teamFile', query: { headNodeId: row.headNodeId, teamId: row.id } })
  // } else {
  //   router.push({ path: '/newUi/teamKnowdge/teamFile', query: { headNodeId: row.headNodeId, teamId: row.id } })
  // }
}
const getTeamTypeCount = () => {
  apiTeamTypeTeamTypeCount().then((res) => {
    res.data.forEach(element => {
      xAxisDataList.value.push(element.name)
      seriesData.value.push(element.count)
    })
    setTeamTypeCountEcharts()
  })
}
const setTeamTypeCountEcharts = () => {
  const myChart = echarts.init(echartsRefs.value)
  myChart.setOption({
    tooltip: {
      trigger: "axis",
      axisPointer: {
        type: "shadow"
      }
    },
    xAxis: {
      type: "category",
      data: xAxisDataList.value,
      axisLabel: {
        show: true, // 是否显示X轴的内容，不包含两端的文字
        interval: 0,
        // rotate: '50', // 旋转50°
        lineHeight: 18,
        formatter: function (params) {
          // console.log('formatter', params, params.length)
          var newParamsName = "" // 最终拼接成的字符串
          var paramsNameNumber = params.length // 实际标签的个数
          var provideNumber = 6 // 每行能显示的字的个数
          // 判断标签的个数是否大于规定的个数， 如果大于，则进行换行处理 如果不大于，即等于或小于，就返回原标签
          if (paramsNameNumber > provideNumber) {
            // ********重点在这里********
            newParamsName = params.substring(0, 6) + ".." // 最终拼成的字符串
          } else {
            // 将旧标签的值赋给新标签
            newParamsName = params
          }
          // 将最终的字符串返回
          return newParamsName
        }
      }
    },
    yAxis: {
      type: "value"
    },
    series: [
      {
        data: seriesData.value,
        type: "bar",
        itemStyle: {
          // 设置柱状图的颜色
          color: "#1890ff"
        }
      }
    ]
  })
  // 给window添加resize监听事件，当平怒尺寸发生变化时重置
  window.addEventListener("resize", () => {
    myChart.resize()
  })
}
onMounted(() => {
  getCommonTeam()
  getDataCount()
  getTeamTypeCount()
})
</script>



<style scoped lang='scss'>
:deep(.el-empty) {
  padding: 0;
}

.page_vue_door {
  // background: #f5f5f5;
  height: calc(100vh - 52px);
  overflow-y: auto;

  .page_header {
    width: 100%;
    height: 200px;
    overflow: hidden;
    background-image: linear-gradient(to bottom, #ccebee, #ffffff);

    .hearder_search {
      width: 600px;
      margin: 0 auto;
      padding: 70px 0 0px;
    }
  }

  .page_body {
    display: flex;
    padding: 20px 80px;
    overflow-x: auto;

    .page_left {
      padding: 16px;
      height: 100%;

      .item_box {
        width: 260px;
        padding: 40px 30px;
        border-radius: 16px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 45px;
        cursor: pointer;

        .item_title {
          .title_text {
            font-size: 16px;
            // font-weight: bold;
            margin-bottom: 8px;
          }
        }

        .item_icon {
          background-color: #ffffff;
          width: 70px;
          height: 70px;
          border-radius: 50%;
          // text-align: center;
          // line-height: 68px;
          display: flex;
          align-items: center;
          justify-content: center;
        }
      }
    }

    .yellow_colour {
      background-color: rgba(247, 207, 47, 0.2);
      color: #f7ce2d;
    }

    .green_colour {
      color: #9bf38e;
      background-color: rgba(154, 243, 142, 0.2);
    }

    .blue_colour {
      color: #29c4f7;
      background-color: rgba(41, 196, 247, 0.2);
    }
  }

  .div_box {
    border-radius: 16px;
    background-color: #ffffff;
    box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.1);
  }

  .page_right {
    margin-left: 30px;
    flex: 1;

    .right_top {
      // width: 100%;
      display: flex;
      height: 300px;

      .recently_tool {
        // width: 400px;
        min-width: 270px;
        max-width: 390px;
        padding: 16px;

        .recently_tool_box {
          display: flex;
          flex-wrap: wrap;
          justify-content: space-between;

          .box_item {
            width: 108px;
            text-align: center;
            padding: 12px 0;
            cursor: pointer;
            margin-right: 6px;

            &:hover {
              background-color: #ecf5ff;
              border-radius: 4px;
            }

            .icon_box {
              font-size: 40px;
            }

            .title {
              color: #1f2329;
              margin-top: 9px;
            }
          }
        }
      }

      .common_team {
        padding: 16px;
        flex: 1;
        margin-left: 30px;
        min-width: 420px;

        .common_team_box {
          display: flex;
          justify-content: space-between;
          align-items: center;
          padding: 6px;
          border-radius: 6px;
          cursor: pointer;

          .teamName {
            display: inline-block;
            font-size: 14px;
            margin-left: 6px;
            color: #1f2329;
          }

          &:hover {
            background-color: #ecf5ff;
          }

          .rightBox {
            display: flex;
            align-items: center;
          }

          .mr {
            margin-right: 40px;
          }
        }

        :deep(.el-progress__text) {
          font-size: 9px !important;

          span {
            padding-right: 5px;
          }
        }
      }

      .div_title {
        font-size: 15px;
        font-weight: bold;
        margin-bottom: 10px;
      }
    }

    .right_bottom_box {
      padding: 16px 16px 0;
      margin-top: 30px;
      overflow-x: auto;
      width: 100%;

      .echarts_class {
        width: 99%;
        height: 280px;
      }
    }
  }

  .peopleBox {
    display: flex;
    align-items: center;
    color: #26292e;
    font-size: 14px;

    .people {
      width: 26px;
      height: 26px;
      border-radius: 13px;
      display: flex;
      align-items: center;
      justify-content: center;
      color: #fff;
      font-size: 12px;
      background-color: #56abfb;
      margin-right: 3px;

      span {
        display: inline-block;
        margin-top: 2px;
        transform: scale(0.9, 0.9);
      }
    }
  }
}
</style>